package com.cim120.commons.cip.process.strategy;

import com.cim120.commons.cip.constant.ImageEnum;
import com.cim120.commons.cip.model.Image;
import com.cim120.commons.utils.FileUtil;

import java.io.File;
import java.util.List;
import java.util.Map;

/**
 * Created by tonydeng on 16/4/27.
 */
public abstract class CropStrategy {
    /**
     * 处理切图业务
     *
     * @param files
     * @return corp status
     */
    public abstract boolean crop(ImageEnum.Type type, List<File> files);

    /**
     * 获得返回处理的图片信息
     *
     * @param results
     * @return Map<String,Image>
     */
    public abstract Map<String, Image> getResultMap(ImageEnum.Type type, Map<String, Image> results);

    /**
     * 根据原图的图片信息获得指定标示的图片信息
     *
     * @param originImage
     * @param flag
     * @return Image
     */
    protected Image getImageInfoByOrigin(Image originImage, String flag) {
        Image im = new Image();
        if (originImage != null) {
            im.setUrl(FileUtil.getFilePathName(originImage.getUrl(), flag));
            im.setFile(new File(FileUtil.getFilePathName(originImage.getFile(), flag)));
        }
        return im;
    }
}
